<?php

/**
 * recommend widget class
 *
 * @since 2.8.0
 */
class recommend extends stwidgets {

    function recommend() {
        $this->WP_Widget(false, $name = 'Mail Recommend');
    }

    function widget($args, $instance) {
        $option = get_option('tvpresident_1_settings');
        if(isset($_POST['recommend'])){
            $recommend = $_POST['recommend'];
            unset($_POST['recommend']);
            $success = true;
        }
        if(isset($recommend)){
            $html = '================================<br/>';
            $html.='<b><u>Company Name:</u></b> '.$recommend['company'].'<br/>';
            $html.='<b><u>President Name:</u></b> '.$recommend['president'].'<br/>';
            $html.='<b><u>Nominators Name:</u></b> '.$recommend['nominator'].'<br/>';
            $html.= '================================';
            $current_site = get_bloginfo('name');
            add_filter( 'wp_mail_content_type', 'set_html_content_type' );
            wp_mail($option['email_contact'], 'President appeared to recommend - '.$current_site, $html);
            remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
        }
        ?>
        <div class="divpresident">
            <div class="divtitle">President appeared to recommend? </div>
            <div class="divcontent">
              <form class="div-recommend" method="post" onsubmit="return check_recommend()">
                <table cellpadding="0px" cellspacing="0px" name="table-pre" width="100%">
                <tr> <td>Company Name:</td><td><input data="company name" type="text" name="recommend[company]"></td></tr>
                <tr> <td>President Name:</td><td><input data="Ppresident name" type="text" name="recommend[president]"></td></tr>
                <tr> <td>Nominators Name:</td><td><input data="nominators name" type="text" name="recommend[nominator]"></td></tr>
                <tr><td colspan="2" style="color:green;text-align: center;padding: 5px;"><?php if(isset($success)){ ?> Sent recommend successful!<?php } ?></td></tr>
                <tr><td></td><td style="" align="right"><input style="font-size: 12px;padding: 0.2em 1.0em 0.12em;" type="submit" value="Send" class=" button black medium buttonsearch"></td></tr>
                </table>
              </form>
            </div>
          </div>
            <script type="text/javascript">
                function check_recommend(){
                    var required = $('.div-recommend input');
                    for(var i=0;i<required.length;i++){
                        var each = required[i];
                         if($(each).val()==''){
                            alert('Please fill '+$(each).attr('data')+'!');
                            $(each).focus();
                            return false;
                        }
                    }
                }
            </script>
        <?php
    }

    function form($instance) {
        
    }

}
